# Teno文件及日志工具
print('------')
from mpython import *
from Teno_Brain.RSaD import *
import os
print('pivot.py')

def p_fle_(name='Null', mode=0, data='Null'): #   设备文件读写，1写0读, 无需输入后缀但仅支持.tnt后缀
    if mode == 0:
        try:
            with open('Teno_Brain/Storage/'+name+'.tnt', 'r') as file:
                data = file.read()
            return data
        except Exception as e:
            print("发生错误: {}".format(e))
            return None
    elif mode == 1:
        try:
            with open('Teno_Brain/Storage/'+name+'.tnt', 'r') as file:
                file.write(data)
        except Exception as e:
        print("发生错误: {}".format(e))

def p_cog_(cog_nam='Null', target_item='Null'):# 配置文件获取
    global cog_nam, cog_val
    with open('Teno_Brain/Storage/'+cog_nam+'.tnt', 'r') as file:
        for line in file:
            cog_nam, cog_val = line.strip().split(':')
            if cog_nam == target_item:
                return cog_nam, cog_val

def p_tnl_(): #   输出已获取的工具列表
    file_list = []
    tools_name = []
    title = 'Null'
    reading = 'Null'
    # 遍历目录下的文件和子目录
    for root, dirs, files in os.walk(tools/Storage):
        for file in files:
            # 将文件名加入到列表中
            file_list.append(os.path.join(root, file))
            with open(file_list[file], 'r') as name:
                for line in name:
                    title, reading =line.strip().split(':')
                    if reading == 'Name':
                        tools_name.append(reading)
    return file_list, tools_name